package convert.types;

import com.aspose.slides.FontsLoader;
import com.aspose.slides.License;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;
import convert.AbstractToPdf;

import java.io.InputStream;
import java.io.OutputStream;

/**
 * Slides转PDF
 * <br>
 * Created by Hong 2024/7/4
 **/
public class SlidesToPdf extends AbstractToPdf {

    private final Presentation presentation;

    public SlidesToPdf(InputStream inputStream) throws Exception {
        this.presentation = new Presentation(inputStream);
    }

    @Override
    public void init() throws Exception {
        License license = new License();
        license.setLicense(getLicense());
    }

    @Override
    protected void fontSettings() {
        if (System.getProperty("os.name").contains("linux")) {
            FontsLoader.loadExternalFonts(new String[]{"/usr/share/fonts/chinese"});
        }
    }

    @Override
    public void toPdf(OutputStream outputStream) throws Exception {
        presentation.save(outputStream, SaveFormat.Pdf);
    }

    @Override
    public void close() {
        if (presentation != null) {
            presentation.dispose();
        }
    }
}
